<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 *
 *
 *
 * @package     h
 * @subpackage  models
 * @category    models
 * @author      hyw
 * @copyright   copyright (c) 2012
 * @filesource
 */
class Client_users_field_model extends Base_model {
    protected $_table_name = 'client_users_field';
    protected $_key_name = 'client_users_field_id';
	
	function get_info($id) {
		if(!empty($id))
			$where[$this->_key_name]=$id;
		$where['dtime']=0;
		return $this->fetch(NULL, $where,NULL,'row');
	}

	function get_users_field($id) {
		if(!empty($id))
			$where['users_id']=$id;
		$where['dtime']=0;
		return $this->fetch(NULL, $where,NULL,'row');
	}

    function get_all() {
		$where=array('dtime'=>0);
		return $this->fetch(NULL, $where);
    }

	function get_all_count() {
		$where=array('dtime'=>0);
		return $this-> fetch(NULL, $where, NULL,"count");
    }

	function get_users_field_count($id) {
		if(!empty($id))
			$where['users_id']=$id;
		$where=array('dtime'=>0);
		return $this-> fetch(NULL, $where, NULL,"count");
    }
	
	function update_data($data) {
		$c=$this->get_users_field_count($data['users_id']);
		if($c>0){
			$value=array('value'=>$data['value'],'mtime'=>time());
			$where[]=array('users_id'=>$data['users_id']);
			return $this->update($value, $where);
		}else{
			$this->add($data);
		}
	}
	function add($data) {		
		$data['ctime']=time();
		return $this->insert ( $data );
	}

	function del($data) {
		$where[]=array($this->_key_name=>$data['id']);
		$value=array('dtime'=>time());
		return $this->update($value, $where);
	}
	
}